import $ from 'jquery';
import Button from './Button';


export default class HrButton extends Button {
  _status() { }

  command() {
    let $newBlock;
    let $hr = $('<hr/>')
    let $rootBlock = this.editor.selection.rootNodes().first();
    let $nextBlock = $rootBlock.next();
    if ($nextBlock.length > 0) this.editor.selection.save();
    else $newBlock = $('<p/>').append(this.editor.util.phBr);
    $hr.insertAfter($rootBlock);
    if ($newBlock) {
      $newBlock.insertAfter($hr);
      this.editor.selection.setRangeAtStartOf($newBlock);
    } else {
      this.editor.selection.restore();
    }
    return this.editor.trigger('valuechanged');
  }
}

HrButton.prototype.name = 'hr';
HrButton.prototype.icon = 'minus';
HrButton.prototype.htmlTag = 'hr';